"""
@File    ：page_repair_management.py
@Author  ：ixiaodu
@Date    ：2024/8/20
@Desc    ：
"""
import allure
from selenium.webdriver import Keys

from common.page_base import Base
from page_element import el_repair_management
from utils.timer import sleep


class PageRepairManagement(Base):
    """报修管理页面"""

    def click_processing(self):
        """点击处理中"""
        self.base_click(el_repair_management.processing)
        sleep()

    def mouse_hover_more_menus(self):
        """鼠标悬停更多菜单"""
        self.base_mouse_hover(el_repair_management.more_menus)
        sleep()

    def click_assigned(self):
        """点击指派"""
        self.base_click(el_repair_management.assigned)
        sleep()

    def select_repair_worker(self):
        """选择维修人员"""
        self.base_click(el_repair_management.repair_worker)
        sleep()

    def click_assigned_submit(self):
        """点击指派提交"""
        self.base_click(el_repair_management.assigned_submit)
        sleep()

    def click_add_repair_order(self):
        """点击添加报修单"""
        self.base_click(el_repair_management.add_repair_order)
        sleep()

    def select_tenants(self):
        """选择租客"""
        self.base_click(el_repair_management.tenants)
        sleep()

    def input_reporter(self, reporter):
        """输入上报人"""
        self.base_click(el_repair_management.reporter)
        self.base_input(el_repair_management.reporter, reporter)
        self.base_click(el_repair_management.reporter_value)
        sleep()

    def select_report_type(self):
        """选择报修类型"""
        self.base_click(el_repair_management.report_type)
        self.base_click(el_repair_management.report_type_value)
        sleep()

    def select_report_project(self):
        """选择报修项目"""
        self.base_click(el_repair_management.report_project)
        self.base_click(el_repair_management.report_project_value)
        sleep()

    def select_latest_repair_time(self):
        """选择最晚维修时间"""
        self.base_click(el_repair_management.latest_repair_time)
        self.base_input(el_repair_management.latest_repair_time, Keys.RIGHT)
        sleep()
        self.base_input(el_repair_management.latest_repair_time, Keys.ENTER)
        sleep()

    def select_process_repair_worker(self):
        """选择报修单维修人员"""
        self.base_click(el_repair_management.process_repair_worker)
        sleep()

    def input_report_content(self, content):
        """输入报修内容"""
        self.base_input(el_repair_management.report_content, content)
        sleep()

    def click_img_upload(self):
        """点击图片上传"""
        self.base_click(el_repair_management.img)
        sleep(2)

    def click_add_repair_order_submit(self):
        """点击添加报修单提交"""
        self.base_click(el_repair_management.add_repair_order_submit)
        sleep()

    def assigned_repair_worker(self):
        """指派维修人员"""
        with allure.step("鼠标悬停更多菜单"):
            self.mouse_hover_more_menus()
        with allure.step("点击指派"):
            self.click_assigned()
        with allure.step("选择维修人员"):
            self.select_repair_worker()
        with allure.step("点击指派提交"):
            self.click_assigned_submit()

    def add_repair_order(self, reporter, content):
        """添加报修单"""
        with allure.step("点击处理中"):
            self.click_processing()
        with allure.step("点击添加报修单"):
            self.click_add_repair_order()
        with allure.step("选择租客"):
            self.select_tenants()
        with allure.step(f"上报人输入{reporter}"):
            self.input_reporter(reporter)
        with allure.step("选择报修类型"):
            self.select_report_type()
        with allure.step("选择报修项目"):
            self.select_report_project()
        with allure.step("选择最晚维修时间"):
            self.select_latest_repair_time()
        with allure.step("选择报修单维修人员"):
            self.select_process_repair_worker()
        with allure.step(f"上报内容输入{content}"):
            self.input_report_content(content)
        with allure.step("点击图片上传"):
            self.click_img_upload()
        with allure.step("点击添加报修单提交"):
            self.click_add_repair_order_submit()

    def get_response_info(self):
        """获取响应信息"""
        sleep()
        return self.base_get_text(el_repair_management.response_info)
